# -*- coding: utf-8 -*-
from five import grok
from zope.interface import Interface
from Products.CMFCore.utils import getToolByName
from Products.bpContents.articulo import IArticulo
from Products.bpContents.galeria import IGaleria
from Products.bpContents.evento import IEvento
from plone.dexterity.interfaces import IDexterityContainer
from zope.component import getMultiAdapter
from zope.component import queryMultiAdapter


class ICreatorInfo(Interface):
    """Devuelve un diccionario la infor del creador de un artículo"""

    def getCreatorInfo(memberId):
        """una nueva cancion"""


    def get_author_image(memberId):
        """devuelve la imagen del avatar"""


class CreatorInfo(grok.Adapter):
    grok.provides(ICreatorInfo)
    grok.context(Interface)


    def getCreatorInfo(self):
        """Devuelve los datos del creador del documento"""

        pm = getToolByName(self.context, 'portal_membership')
        creador = pm.getMemberById(self.context.Creator())
        creadorImg = self.get_author_image(self.context.Creator())
        datos = dict()
        datos["nombre"] = creador.getProperty("fullname")
        datos["email"] = creador.getProperty("email")
        datos["portrait"] = creadorImg
        return datos


    def get_author_image(self, member_id):
        """
        Fetch the author portrait image url accoding to member_id
        """
        mtool = getToolByName(self.context, 'portal_membership')
        return mtool.getPersonalPortrait(id=member_id)



